Skip to content

Готовая задача с генериками#12

Open
Palezehvat wants to merge 2 commits intomasterfrom
FilterFoldMap
Open

Готовая задача с генериками#12
Palezehvat wants to merge 2 commits intomasterfrom
FilterFoldMap

Conversation

@Palezehvat
Copy link
Owner

Задача на filter fold map


class Program
{
public static void Main()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не нужно, уберите :)

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все три функции на самом деле должны быть в одном классе, а у Вас аж три отдельных (!) проекта с тестами. Упростите структуру решения, пожалуйста :)

/// <summary>
/// Implements the filter function
/// </summary>
public class FilterList

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут и ниже не хватает static-ов, потому как у класса нет своего состояния.

{
if (list == null)
{
return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А нельзя так. Кидайте исключение

{
return null;
}
List<TypeOfValue> newList = new List<TypeOfValue>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
List<TypeOfValue> newList = new List<TypeOfValue>();
List<TypeOfValue> newList = new();

/// <param name="accumulatedValue">Cumulative value with the selected type</param>
/// <param name="function">A function for accumulating a value, takes an accumulating value and a list item</param>
/// <returns>Accumulated value</returns>
public TypeOfValue Fold<TypeOfValue>(List<TypeOfValue> list, TypeOfValue accumulatedValue, Func<TypeOfValue, TypeOfValue, TypeOfValue> function)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно более общий тип, потому что тип результата не обязан совпадать с типом значений в списке

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments